const {
    Msg,
    Code,
    Constant,
    RedisPrefix
} = require('./consts');
const {
    getUserInfo,    // 用户是否存在
    addUserOil,      //增加用户的石油
    apiAddUserApprenticeOil, //增加徒弟石油贡献
    apiAddUserDiscipleOil, //增加徒孙石油贡献
} = require('./api');
const {
    checkDailyMission,    //任务是否存在
    getDailyMission, //获取任务信息
    saveMission, //初始化日常任务
    getAchievementMission, //获取成就任务信息
    updAchievementMission,
    getSurplusProfit, //获取分红剩余
    getTotalProfit, //获取分红总量
    getPersonProfit,
    setYesterdayTotalOil,
    setPersonProfit,
    getYesterdayTotalOil,
    receiveProfit,
    isReceiveDailyBalance,
    saveReceiveDailyBalance,
    userTotalVideo,
    increaseTotalVideo,
    checkFinishTask,
    saveFinish,
    validSonNumber,
    isValidSon
} = require('./cache');
const {
    sonCount,//获取徒弟数量
    getDailyOil,
    getDailyTotalOil,
    insertAchievement,
    saveDailyWithdraw,
    haveSonUser
} = require('../lib/dao');
const {
    apiGetUserMoneyAndOil,
    apiGetTotalWithdraw
} = require('../../player/lib/api');
const User = require('../../login/lib/userSchema');
const time = require('../../../util/time');


/**
 * 查询用户日常任务是否存在
 * @param session
 * @param uid
 * @returns {Promise<unknown>}
 */
exports.missionExists = async function ({session, uid}) {
    //判断用户是否存在
    let userInfo = await getUserInfo.call(this, session, uid);
    if (!userInfo) {
        throw new Error(Msg.USER_NOT_FOUND);
    }
    //从redis中检查日常任务是否存在
    let exists = await checkDailyMission.call(this, uid);
    return exists;
}

/**
 * 获取任务信息
 * @param session
 * @param uid
 * @returns {Promise<void>}
 */
exports.getMissionInfo = async function (session, uid) {
    let mission = await getDailyMission.call(this, uid);
    return {
        mission: mission,
        reward: {
            invite: {
                number: 20,
                type: 'oil'
            },
            son: {
                number: 8,
                type: 'oil'
            },
            grand_son: {
                number: 4,
                type: 'oil'
            }
        }
    };
}

/**
 * 获取今日分红信息
 * @param session
 * @param uid
 * @returns {Promise<void>}
 */
exports.getProfitAction = async function (session, uid) {
    let yesterday_total_oil = await getYesterdayTotalOil.call(this);
    if (!yesterday_total_oil) {
        yesterday_total_oil = await getDailyTotalOil.call(this, time.unixToDate(time.yesterdayZeroClockUnix()), time.unixToDate(time.todayZeroClockUnix()));
        if (yesterday_total_oil === 0) throw new Error(Msg.NOT_SEND_PROFIT);
        await setYesterdayTotalOil.call(this, yesterday_total_oil);
    }
    let total = await getTotalProfit.call(this);
    if (total === 0) throw new Error(Msg.NOT_SEND_PROFIT);
    let surplus = await getSurplusProfit.call(this);
    let own = await getPersonProfit.call(this, uid);
    if (!own) {
        let yesterday_oil = await getDailyOil.call(this, uid, time.unixToDate(time.yesterdayZeroClockUnix()), time.unixToDate(time.todayZeroClockUnix()));
        if (yesterday_oil <= 0) {
            own = 50;
        } else {
            own = total * (yesterday_oil / yesterday_total_oil);
            own = Math.floor(own);
            if (own < 50) own = 50;
        }
        await setPersonProfit.call(this, uid, own);
    }

    return {
        total: total,
        surplus: surplus,
        own: own
    };
}

/**
 * 初始化用户日常任务信息
 * @param session
 * @param uid
 * @returns {Promise<void>}
 */
exports.initDailyMission = async function ({session, uid}) {
    let newMission = {
        uid: uid,
        invite_reward: 0,
        friends_video_reward: 0,
        grand_son_video_reward: 0,
        personal_video_reward: 0,
        money_video_reward: 0,
        gmt_create: Date.now(),
        gmt_modified: Date.now()
    };
    await saveMission.call(this, newMission);
}

/**
 * 用户领取邀请好友得到的石油
 * @param session
 * @param uid
 * @returns {Promise<void>}
 */
exports.receiveInviteReward = async function ({session, uid}) {
    //判断用户是否存在
    let userInfo = await getUserInfo.call(this, session, uid);
    if (!userInfo) {
        throw new Error(Msg.USER_NOT_FOUND);
    }
    if (!await checkDailyMission.call(this, uid)) throw new Error(Msg.MISSION_UNDEFINED);
    let mission = await getDailyMission.call(this, uid);
    if (mission.invite_reward <= 0) throw new Error(Msg.REWARD_NUM_INSUFFICIENT);
    mission.invite_reward = (mission.invite_reward - 1) < 0 ? 0 : mission.invite_reward - 1;
    await saveMission.call(this, mission);
    await addUserOil.call(this, session, uid, Constant.OIL_INVITE_NUM, Constant.OIL_SOURCE_INVITE);
    //增加徒弟石油贡献
    await apiAddUserApprenticeOil.call(this, session, uid, Constant.OIL_INVITE_NUM);
}

/**
 * 领取徒弟观看视频得到的石油奖励
 * @param session
 * @param uid
 * @returns {Promise<void>}
 */
exports.receiveSonVideoReward = async function ({session, uid}) {
    //判断用户是否存在
    let userInfo = await getUserInfo.call(this, session, uid);
    if (!userInfo) {
        throw new Error(Msg.USER_NOT_FOUND);
    }
    if (!await checkDailyMission.call(this, uid)) throw new Error(Msg.MISSION_UNDEFINED);
    let mission = await getDailyMission.call(this, uid);
    if (mission.friends_video_reward <= 0) throw new Error(Msg.REWARD_NUM_INSUFFICIENT);
    mission.friends_video_reward = (mission.friends_video_reward - 1) < 0 ? 0 : mission.friends_video_reward - 1;
    await saveMission.call(this, mission);
    await addUserOil.call(this, session, uid, Constant.OIL_SON_NUM, Constant.OIL_SOURCE_SON);
    //增加徒弟石油贡献
    await apiAddUserApprenticeOil.call(this, session, uid, Constant.OIL_SON_NUM);
}

/**
 * 领取徒孙观看视频得到的石油奖励
 * @param session
 * @param uid
 * @returns {Promise<void>}
 */
exports.receiveGrandSonVideoReward = async function ({session, uid}) {
    //判断用户是否存在
    let userInfo = await getUserInfo.call(this, session, uid);
    if (!userInfo) {
        throw new Error(Msg.USER_NOT_FOUND);
    }
    if (!await checkDailyMission.call(this, uid)) throw new Error(Msg.MISSION_UNDEFINED);
    let mission = await getDailyMission.call(this, uid);
    if (mission.grand_son_video_reward <= 0) throw new Error(Msg.REWARD_NUM_INSUFFICIENT);
    mission.grand_son_video_reward = (mission.grand_son_video_reward - 1) < 0 ? 0 : mission.grand_son_video_reward - 1;
    await saveMission.call(this, mission);
    await addUserOil.call(this, session, uid, Constant.OIL_GRANDSON_NUM, Constant.OIL_SOURCE_GRANDSON);
    //增加徒弟石油贡献
    await apiAddUserDiscipleOil.call(this, session, uid, Constant.OIL_GRANDSON_NUM);
}

/**
 * 领取每日0.3元奖励
 * @param session
 * @param uid
 * @returns {Promise<void>}
 */
exports.receiveMoneyVideoReward = async function ({session, uid}) {
    //判断用户是否存在
    let userInfo = await getUserInfo.call(this, session, uid);
    if (!userInfo) {
        throw new Error(Msg.USER_NOT_FOUND);
    }
    if (!await checkDailyMission.call(this, uid)) throw new Error(Msg.MISSION_UNDEFINED);
    let mission = await getDailyMission.call(this, uid);
    if (mission.money_video_reward != 1) throw new Error(Msg.REWARD_NUM_INSUFFICIENT);
    mission.money_video_reward = 2;
    //更新任务为领取状态
    await saveMission.call(this, mission);
    //累积提现总额
    let total_withdraw = await apiGetTotalWithdraw.call(this, session, uid);
    //数据库的金额
    let {total_money} = await apiGetUserMoneyAndOil.call(this, session, uid);
    //保存提现记录
    await saveDailyWithdraw.call(this, uid, userInfo.real_open_id, total_withdraw, total_money);
}

/**
 * 领取用户自己看视频得到的石油奖励
 * @param session
 * @param uid
 * @returns {Promise<void>}
 */
exports.receivePersonalVideoReward = async function ({session, uid}) {
    //已经领取过今日的分红奖励
    let ret = await isReceiveDailyBalance.call(this, uid);
    if (ret) {
        throw new Error(Msg.REWARD_RECEIVED);
    }
    //用户的分红奖励石油
    let oil = await getPersonProfit.call(this, uid);
    if (!oil) {
        throw new Error(Msg.NOT_SEND_PROFIT);
    }
    //抢分红
    let res = await receiveProfit.call(this, oil);
    if (res == -1) {
        throw new Error(Msg.NOT_ENOUGH);
    }
    //判断用户是否存在
    let userInfo = await getUserInfo.call(this, session, uid);
    if (!userInfo) {
        throw new Error(Msg.USER_NOT_FOUND);
    }
    if (!await checkDailyMission.call(this, uid)) throw new Error(Msg.MISSION_UNDEFINED);
    let mission = await getDailyMission.call(this, uid);
    if (mission.personal_video_reward == 0) throw new Error(Msg.MISSION_INCOMPLETE);
    if (mission.personal_video_reward == 2) throw new Error(Msg.REWARD_RECEIVED);
    mission.personal_video_reward = 2;
    //保存领取记录
    await saveReceiveDailyBalance.call(this, uid);
    await saveMission.call(this, mission);
    // await addUserOil.call(this, session, uid, Constant.OIL_PERSONAL_NUM, Constant.OIL_SOURCE_PERSONAL);
    await addUserOil.call(this, session, uid, oil, Constant.OIL_SOURCE_PERSONAL);
}

/**
 * 用户日常任务邀请领奖次数增加
 * @param uid
 * @returns {Promise<void>}
 */
exports.increaseInvite = async function (parent_id, uid) {
    let ret = await isValidSon.call(this, parent_id, uid);
    //是新的有效徒弟
    if (ret) {
        let mission = {
            uid: parent_id,
            invite_reward: 1,
            friends_video_reward: 0,
            grand_son_video_reward: 0,
            personal_video_reward: 0,
            money_video_reward: 0,
            gmt_create: Date.now(),
            gmt_modified: Date.now()
        };
        //如果任务存在则在对应字段 invite_reward 加一
        if (await checkDailyMission.call(this, parent_id)) {
            mission = await getDailyMission.call(this, parent_id);
            mission.invite_reward = Number(mission.invite_reward) + 1;
        }
        await saveMission.call(this, mission);
    }
}

/**
 * 用户日常任务徒弟观看视频领奖次数增加
 * @param uid
 * @returns {Promise<void>}
 */
exports.increaseFriendsReward = async function (uid) {
    let mission = {
        uid: uid,
        invite_reward: 0,
        friends_video_reward: 1,
        grand_son_video_reward: 0,
        personal_video_reward: 0,
        money_video_reward: 0,
        gmt_create: Date.now(),
        gmt_modified: Date.now()
    };
    //如果任务存在则在对应字段 friends_video_reward 加一
    if (await checkDailyMission.call(this, uid)) {
        mission = await getDailyMission.call(this, uid);
        mission.friends_video_reward = Number(mission.friends_video_reward) + 1;
    }
    await saveMission.call(this, mission);
}

/**
 * 用户日常任务徒孙观看视频领奖次数增加
 * @param uid
 * @returns {Promise<void>}
 */
exports.increaseGrandSonReward = async function (uid) {
    let mission = {
        uid: uid,
        invite_reward: 0,
        friends_video_reward: 0,
        grand_son_video_reward: 1,
        personal_video_reward: 0,
        money_video_reward: 0,
        gmt_create: Date.now(),
        gmt_modified: Date.now()
    };
    //如果任务存在则在对应字段 grand_son_video_reward 加一
    if (await checkDailyMission.call(this, uid)) {
        mission = await getDailyMission.call(this, uid);
        mission.grand_son_video_reward = Number(mission.grand_son_video_reward) + 1;
    }
    await saveMission.call(this, mission);
}

/**
 * 将日常任务的用户个人视频奖励更新为带领取状态
 * @param uid
 * @returns {Promise<void>}
 */
exports.increasePersonalReward = async function (uid) {
    let mission = {
        uid: uid,
        invite_reward: 0,
        friends_video_reward: 0,
        grand_son_video_reward: 0,
        personal_video_reward: 1,
        money_video_reward: 0,
        gmt_create: Date.now(),
        gmt_modified: Date.now()
    };
    //如果任务存在则在对应字段 personal_video_reward 为待领取状态
    if (await checkDailyMission.call(this, uid)) {
        mission = await getDailyMission.call(this, uid);
        if (mission.personal_video_reward == 0) {
            mission.personal_video_reward = 1;
        }
    }
    await saveMission.call(this, mission);
}

/**
 * 更新money_video_reward字段
 * @param uid
 * @returns {Promise<void>}
 */
exports.increaseMoneyReward = async function (uid) {
    let mission = {
        uid: uid,
        invite_reward: 0,
        friends_video_reward: 0,
        grand_son_video_reward: 0,
        personal_video_reward: 0,
        money_video_reward: 1,
        gmt_create: Date.now(),
        gmt_modified: Date.now()
    };
    //如果任务存在则在对应字段 money_video_reward 为待领取状态
    if (await checkDailyMission.call(this, uid)) {
        mission = await getDailyMission.call(this, uid);
        if (mission.money_video_reward == 0) {
            mission.money_video_reward = 1;
        }
    }
    await saveMission.call(this, mission);
}

/**
 * 增加用户的总视频次数
 * @param uid
 * @returns {Promise<void>}
 */
exports.increaseUserTotalVideo = async function (uid) {
    await increaseTotalVideo.call(this, uid);
}

/**
 * 获取成就任务信息
 * @param session
 * @param uid
 * @returns {Promise<unknown>}
 */
exports.achievementMissionAction = async function ({session, uid}) {
    //判断用户是否存在
    let userInfo = await getUserInfo.call(this, session, uid);
    if (!userInfo) {
        throw new Error(Msg.USER_NOT_FOUND);
    }
    let mission = await getAchievementMission.call(this, uid);
    //获取徒弟数量
    let son_count = await validSonNumber.call(this, uid);
    //总视频数量
    let total_video = await userTotalVideo.call(this, uid);
    if (!mission) {
        //初始化任务
        mission = {
            task_one: {
                desc: '累积邀请50名用户\n且每名用户看够30次视频',
                need: 50,
                current: son_count,
                is_finish: (son_count >= 50) ? true : false,
                receive: false,
                reward: 50
            },
            task_two: {
                desc: '累积邀请100名用户\n且每名用户看够30次视频',
                need: 100,
                current: son_count,
                is_finish: (son_count >= 100) ? true : false,
                receive: false,
                reward: 120
            },
            task_three: {
                desc: '累积邀请200名用户\n且每名用户看够30次视频',
                need: 200,
                current: son_count,
                is_finish: (son_count >= 200) ? true : false,
                receive: false,
                reward: 240
            },
            task_four: {
                desc: '自己累积观看1000次视频',
                need: 1000,
                current: total_video,
                is_finish: (total_video >= 1000) ? true : false,
                receive: false,
                reward: 60
            },
            task_five: {
                desc: '自己累积观看3000次视频',
                need: 3000,
                current: total_video,
                is_finish: (total_video >= 3000) ? true : false,
                receive: false,
                reward: 200
            }
        }
    } else {
        if (!mission.task_one.is_finish) {
            mission.task_one.is_finish = (son_count >= 50) ? true : false;
            mission.task_one.current = (son_count >= 50) ? 50 : son_count;
        }
        if (!mission.task_two.is_finish) {
            mission.task_two.is_finish = (son_count >= 100) ? true : false;
            mission.task_two.current = (son_count >= 100) ? 100 : son_count;
        }
        if (!mission.task_three.is_finish) {
            mission.task_three.is_finish = (son_count >= 200) ? true : false;
            mission.task_three.current = (son_count >= 200) ? 200 : son_count;
        }
        if (!mission.task_four.is_finish) {
            mission.task_four.is_finish = (total_video >= 1000) ? true : false;
            mission.task_four.current = (total_video >= 1000) ? 1000 : total_video;
        }
        if (!mission.task_five.is_finish) {
            mission.task_five.is_finish = (total_video >= 3000) ? true : false;
            mission.task_five.current = (total_video >= 3000) ? 3000 : total_video;
        }
    }
    //更新成就任务
    await updAchievementMission.call(this, uid, mission);

    return [
        mission.task_one,
        mission.task_two,
        mission.task_three,
        mission.task_four,
        mission.task_five
    ];
}

/**
 * 领取奖励
 * @param session
 * @param uid
 * @param task
 * @returns {Promise<void>}
 */
exports.receiveAchievementRewardAction = async function ({session, uid, task}) {
    let self = this;
    //判断用户是否存在
    let userInfo = await getUserInfo.call(this, session, uid);
    if (!userInfo) {
        throw new Error(Msg.USER_NOT_FOUND);
    }
    let mission = await getAchievementMission.call(this, uid);

    switch (task) {
        case 1:
            if (mission.task_one.is_finish && !mission.task_one.receive) {
                mission.task_one.receive = true;
                //更新成就任务
                await updAchievementMission.call(self, uid, mission);
                //发起领取申请
                await insertAchievement.call(self, uid, 'task_one', mission);
            } else {
                throw new Error(Msg.MISSION_INCOMPLETE);
            }
            break;
        case 2:
            if (mission.task_two.is_finish && !mission.task_two.receive) {
                mission.task_two.receive = true;
                //更新成就任务
                await updAchievementMission.call(self, uid, mission);
                //发起领取申请
                await insertAchievement.call(self, uid, 'task_two', mission);
            } else {
                throw new Error(Msg.MISSION_INCOMPLETE);
            }
            break;
        case 3:
            if (mission.task_three.is_finish && !mission.task_three.receive) {
                mission.task_three.receive = true;
                //更新成就任务
                await updAchievementMission.call(self, uid, mission);
                //发起领取申请
                await insertAchievement.call(self, uid, 'task_three', mission);
            } else {
                throw new Error(Msg.MISSION_INCOMPLETE);
            }
            break;
        case 4:
            if (mission.task_four.is_finish && !mission.task_four.receive) {
                mission.task_four.receive = true;
                //更新成就任务
                await updAchievementMission.call(self, uid, mission);
                //发起领取申请
                await insertAchievement.call(self, uid, 'task_four', mission);
            } else {
                throw new Error(Msg.MISSION_INCOMPLETE);
            }
            break;
        case 5:
            if (mission.task_five.is_finish && !mission.task_five.receive) {
                mission.task_five.receive = true;
                //更新成就任务
                await updAchievementMission.call(self, uid, mission);
                //发起领取申请
                await insertAchievement.call(self, uid, 'task_five', mission);
            } else {
                throw new Error(Msg.MISSION_INCOMPLETE);
            }
            break;
        default:
            throw new Error(Msg.MISSION_UNDEFINED);
            break;
    }
    return;
}

/**
 * 增加用户的有效徒弟数量
 * @param parent_id
 * @param uid
 * @returns {Promise<void>}
 */
exports.increaseValidUserAction = async function (parent_id, uid) {
    await saveFinish.call(this, parent_id, uid);
}

exports.test = async function ({session, uid}) {
    let self = this;
    let users = await haveSonUser.call(self);
    console.log('users.length')
    console.log(users.length)

    for (let i = 0; i < users.length; i++) {
        let data = users[i];
        if (data.parent_id != "0") {
            let f1 = await checkFinishTask.call(self, RedisPrefix.DAILY_MISSION_PREFIX + "2020_07_04", data.uid);
            if (f1) {
                await saveFinish.call(self, data.parent_id, data.uid);
            } else {
                let f2 = await checkFinishTask.call(self, RedisPrefix.DAILY_MISSION_PREFIX + "2020_07_05", data.uid);
                if (f2) {
                    await saveFinish.call(self, data.parent_id, data.uid);
                } else {
                    let f3 = await checkFinishTask.call(self, RedisPrefix.DAILY_MISSION_PREFIX + "2020_07_05", data.uid);
                    if (f3) {
                        await saveFinish.call(self, data.parent_id, data.uid);
                    } else {
                        let f4 = await checkFinishTask.call(self, RedisPrefix.DAILY_MISSION_PREFIX + "2020_07_06", data.uid);
                        if (f4) {
                            await saveFinish.call(self, data.parent_id, data.uid);
                        } else {
                            let f5 = await checkFinishTask.call(self, RedisPrefix.DAILY_MISSION_PREFIX + "2020_07_07", data.uid);
                            if (f5) {
                                await saveFinish.call(self, data.parent_id, data.uid);
                            } else {
                                let f6 = await checkFinishTask.call(self, RedisPrefix.DAILY_MISSION_PREFIX + "2020_07_08", data.uid);
                                if (f6) {
                                    await saveFinish.call(self, data.parent_id, data.uid);
                                } else {
                                    let f7 = await checkFinishTask.call(self, RedisPrefix.DAILY_MISSION_PREFIX + "2020_07_09", data.uid);
                                    if (f7) {
                                        await saveFinish.call(self, data.parent_id, data.uid);
                                    } else {
                                        let f8 = await checkFinishTask.call(self, RedisPrefix.DAILY_MISSION_PREFIX + "2020_07_10", data.uid);
                                        if (f8) {
                                            await saveFinish.call(self, data.parent_id, data.uid);
                                        } else {
                                            let f9 = await checkFinishTask.call(self, RedisPrefix.DAILY_MISSION_PREFIX + "2020_07_11", data.uid);
                                            if (f9) {
                                                await saveFinish.call(self, data.parent_id, data.uid);
                                            } else {
                                                let f10 = await checkFinishTask.call(self, RedisPrefix.DAILY_MISSION_PREFIX + "2020_07_12", data.uid);
                                                if (f10) {
                                                    await saveFinish.call(self, data.parent_id, data.uid);
                                                } else {
                                                    let f11 = await checkFinishTask.call(self, RedisPrefix.DAILY_MISSION_PREFIX + "2020_07_13", data.uid);
                                                    if (f11) {
                                                        await saveFinish.call(self, data.parent_id, data.uid);
                                                    } else {
                                                        let f12 = await checkFinishTask.call(self, RedisPrefix.DAILY_MISSION_PREFIX + "2020_07_14", data.uid);
                                                        if (f12) {
                                                            await saveFinish.call(self, data.parent_id, data.uid);
                                                        } else {
                                                            let f13 = await checkFinishTask.call(self, RedisPrefix.DAILY_MISSION_PREFIX + "2020_07_15", data.uid);
                                                            if (f13) {
                                                                await saveFinish.call(self, data.parent_id, data.uid);
                                                            } else {
                                                                let f14 = await checkFinishTask.call(self, RedisPrefix.DAILY_MISSION_PREFIX + "2020_07_16", data.uid);
                                                                if (f14) {
                                                                    await saveFinish.call(self, data.parent_id, data.uid);
                                                                } else {
                                                                    let f15 = await checkFinishTask.call(self, RedisPrefix.DAILY_MISSION_PREFIX + "2020_07_17", data.uid);
                                                                    if (f15) {
                                                                        await saveFinish.call(self, data.parent_id, data.uid);
                                                                    } else {
                                                                        let f16 = await checkFinishTask.call(self, RedisPrefix.DAILY_MISSION_PREFIX + "2020_07_18", data.uid);
                                                                        if (f16) {
                                                                            await saveFinish.call(self, data.parent_id, data.uid);
                                                                        } else {
                                                                            let f17 = await checkFinishTask.call(self, RedisPrefix.DAILY_MISSION_PREFIX + "2020_07_19", data.uid);
                                                                            if (f17) {
                                                                                await saveFinish.call(self, data.parent_id, data.uid);
                                                                            } else {
                                                                                let f18 = await checkFinishTask.call(self, RedisPrefix.DAILY_MISSION_PREFIX + "2020_07_20", data.uid);
                                                                                if (f18) {
                                                                                    await saveFinish.call(self, data.parent_id, data.uid);
                                                                                } else {
                                                                                    let f19 = await checkFinishTask.call(self, RedisPrefix.DAILY_MISSION_PREFIX + "2020_07_21", data.uid);
                                                                                    if (f19) {
                                                                                        await saveFinish.call(self, data.parent_id, data.uid);
                                                                                    } else {
                                                                                        let f21 = await checkFinishTask.call(self, RedisPrefix.DAILY_MISSION_PREFIX + "2020_07_22", data.uid);
                                                                                        if (f21) {
                                                                                            await saveFinish.call(self, data.parent_id, data.uid);
                                                                                        } else {
                                                                                            let f22 = await checkFinishTask.call(self, RedisPrefix.DAILY_MISSION_PREFIX + "2020_07_23", data.uid);
                                                                                            if (f22) {
                                                                                                await saveFinish.call(self, data.parent_id, data.uid);
                                                                                            } else {
                                                                                                let f23 = await checkFinishTask.call(self, RedisPrefix.DAILY_MISSION_PREFIX + "2020_07_24", data.uid);
                                                                                                if (f23) {
                                                                                                    await saveFinish.call(self, data.parent_id, data.uid);
                                                                                                } else {
                                                                                                    let f24 = await checkFinishTask.call(self, RedisPrefix.DAILY_MISSION_PREFIX + "2020_07_25", data.uid);
                                                                                                    if (f24) {
                                                                                                        await saveFinish.call(self, data.parent_id, data.uid);
                                                                                                    } else {
                                                                                                        let f25 = await checkFinishTask.call(self, RedisPrefix.DAILY_MISSION_PREFIX + "2020_07_26", data.uid);
                                                                                                        if (f25) {
                                                                                                            await saveFinish.call(self, data.parent_id, data.uid);
                                                                                                        } else {
                                                                                                            let f27 = await checkFinishTask.call(self, RedisPrefix.DAILY_MISSION_PREFIX + "2020_07_27", data.uid);
                                                                                                            if (f27) {
                                                                                                                await saveFinish.call(self, data.parent_id, data.uid);
                                                                                                            }
                                                                                                        }
                                                                                                    }
                                                                                                }
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        console.log('执行第' + i + '条数据')
    }
    console.log('执行完毕')

    return;
}